<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>filter</div>
  <script>
    let arr = [1, 2, 3, 4, 5, 6]
    const arr1 = arr.filter(item => {
      return item > 3
    })
    console.log(arr1);
    // 自己封装filter方法
    function selfForeach(arr, cb) {
      let newArr = []
      for (let i = 0; i < arr.length; i++) {
        let res = cb(arr[i], i)
        if (res) {
          newArr.push(arr[i])
        }
      }
      return newArr
    }
    const arr2 = selfForeach(arr, (item, index) => {
      return item >4
    })
    console.log(arr2);
  </script>
</body>

</html>